<template>
  <div class="novel-card" @click="emit('select', novel)">
    <div class="novel-cover">
      <div class="cover-image" :style="coverImageStyle">
        <img v-if="novel.cover_image" :src="novel.cover_image" :alt="novel.title" class="cover-img" />
        <div v-else class="novel-icon">{{ novel.icon }}</div>
        <div class="cover-overlay">
          <div class="overlay-content">
            <el-button type="primary" size="large" class="enter-btn">
              <el-icon><ChatLineRound /></el-icon>
              {{ t('novel.enterWorld') }}
            </el-button>
          </div>
        </div>
      </div>
      <div class="novel-badge">{{ novel.status }}</div>
    </div>
    <div class="novel-info">
      <h3>{{ novel.title }}</h3>
      <p class="novel-author">{{ t('novel.author') }}：{{ novel.author }}</p>
      <p class="novel-desc">{{ novel.description }}</p>
      <div class="novel-stats">
        <div class="stat-tag">
          <el-icon><ChatLineRound /></el-icon>
          {{ novel.characters?.length || 0 }}{{ t('novel.characters') }}
        </div>
        <div class="stat-tag">
          📖 {{ novel.chapters }}{{ t('novel.chapters') }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { ChatLineRound } from '@element-plus/icons-vue'
import type { Novel } from '../../types/novel'

interface Props {
  novel: Novel
}

const props = defineProps<Props>()
const { t } = useI18n()
const emit = defineEmits<{
  select: [novel: Novel]
}>()

const coverImageStyle = computed(() => {
  if (props.novel.cover_image) {
    return {}
  }
  return { background: props.novel.gradient }
})
</script>

<script lang="ts">
export default {
  name: 'NovelCard'
}
</script>

<style scoped>
.novel-card {
  background: white;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 
    0 10px 50px rgba(0, 0, 0, 0.15),
    0 4px 20px rgba(102, 126, 234, 0.1);
  cursor: pointer;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 3px solid transparent;
  position: relative;
  background-clip: padding-box;
}

.novel-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea, #764ba2, #667eea);
  background-size: 200% 200%;
  border-radius: 24px;
  z-index: -1;
  opacity: 0;
  transition: all 0.4s ease;
  animation: gradientShift 6s ease-in-out infinite;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.novel-card::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  right: 3px;
  bottom: 3px;
  background: white;
  border-radius: 21px;
  z-index: -1;
}

.novel-card:hover {
  transform: translateY(-12px) scale(1.03);
  box-shadow: 
    0 20px 80px rgba(102, 126, 234, 0.25),
    0 8px 40px rgba(0, 0, 0, 0.15);
}

.novel-card:hover::before {
  opacity: 1;
}

.novel-card:hover .cover-overlay {
  opacity: 1;
}

.novel-cover {
  position: relative;
  height: 200px;
}

.cover-image {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

.novel-icon {
  font-size: 72px;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.3));
  z-index: 2;
  position: relative;
  animation: iconFloat 6s ease-in-out infinite;
}

@keyframes iconFloat {
  0%, 100% { 
    transform: translateY(0px) rotate(0deg) scale(1); 
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.3));
  }
  25% { 
    transform: translateY(-12px) rotate(3deg) scale(1.05); 
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.4));
  }
  50% { 
    transform: translateY(-6px) rotate(0deg) scale(1.02); 
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.35));
  }
  75% { 
    transform: translateY(4px) rotate(-3deg) scale(0.98); 
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25));
  }
}

.cover-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 3;
}

.overlay-content {
  text-align: center;
}

.enter-btn {
  font-size: 16px;
  padding: 12px 24px;
  border-radius: 25px;
  background: white;
  color: #667eea;
  border: none;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(255, 255, 255, 0.3);
}

.novel-badge {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.9);
  color: #667eea;
  padding: 6px 14px;
  border-radius: 15px;
  font-size: 12px;
  font-weight: 600;
  z-index: 4;
  backdrop-filter: blur(10px);
}

.novel-info {
  padding: 24px;
}

.novel-info h3 {
  font-size: 22px;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 8px;
}

.novel-author {
  font-size: 14px;
  color: #667eea;
  margin-bottom: 12px;
  font-weight: 500;
}

.novel-desc {
  font-size: 14px;
  color: #4b5563;
  line-height: 1.6;
  margin-bottom: 20px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.novel-stats {
  display: flex;
  gap: 12px;
}

.stat-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 500;
}
</style> 